package com.itheima.dubbo.mysql.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.commons.model.domain.SubjectOption;
import com.itheima.dubbo.interfaces.SubjectOptionApi;
import com.itheima.dubbo.mysql.mapper.SubjectOptionMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@Service
public class SubjectOptionApiImpl implements SubjectOptionApi {

    @Autowired
    private SubjectOptionMapper subjectOptionMapper;

    /**
     * 根据选项sid，获取该选项信息
     * @param sid
     * @return
     */
    @Override
    public SubjectOption queryBySid(Long sid) {
        SubjectOption subjectOption = subjectOptionMapper.selectOne(Wrappers
                .lambdaQuery(SubjectOption.class)
                .eq(SubjectOption::getSid, sid));
        return subjectOption;
    }

    /**
     * 根据所属题目id，获取该题目所有选项
     * @param id
     * @return
     */
    @Override
    public List<SubjectOption> querySubjectOption(Long id) {
        return subjectOptionMapper.selectList(Wrappers
                .lambdaQuery(SubjectOption.class)
                .eq(SubjectOption::getId,id));
    }
}
